﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.BusinessService;
using Fuse8.DomainFramework.CacheService;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public abstract class CmsLocalizedEntityObject : CmsPublishedEntityObject, ILocalizedEntityObject
    {
        #region Linked fields

        private CmsSystemLanguage _systemLanguage;

        #endregion

        #region Properties

        public virtual int? SystemLanguageId { get; set; }

        #endregion

        #region Linked properties

        [XmlIgnore]
        [ScriptIgnore]
        public CmsSystemLanguage SystemLanguage
        {
            get
            {
                if (_systemLanguage == null)
                {
                    if (SystemLanguageId.HasValue && SystemLanguageId != 0)
                    {
                        var businessFacade = new BusinessServiceFacade<CmsSystemLanguage, int>();
                        if (businessFacade != null)
                        {
                            _systemLanguage = businessFacade.FindOne(SystemLanguageId.GetValueOrDefault(0));
                        }
                    }
                }
                return _systemLanguage;
            }
            set
            {
                SystemLanguageId = value != null ? value.Id : 0;

                _systemLanguage = null;
            }
        }

        #endregion
    }
}
